package com.lexed.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.lexed.dao.Mapper;
import com.lexed.pojo.Emp;

public class Main {

	public static String diver="";
	public static String url="";
	public static String username="";
	public static String password="";
	
	public static Connection connection ;
	
	public static Map<String, String> sqlanger = new HashMap(); 
	
	public static void main(String[] args) throws Exception {
		
		SAXReader reader = new SAXReader();
		
		Document document = reader.read("youbatis.xml");
		
		Element environment = (Element)document.selectSingleNode("//environment");
		
		Element driverElement = (Element)environment.selectSingleNode("driver");
		Element urlElement = (Element)environment.selectSingleNode("url");
		Element usernameElement = (Element)environment.selectSingleNode("username");
		Element passwordElement = (Element)environment.selectSingleNode("password");
		
		diver = driverElement.getTextTrim();
		url = urlElement.getTextTrim();
		username = usernameElement.getTextTrim();
		password = passwordElement.getTextTrim();
		
		Class.forName(diver);
		connection = DriverManager.getConnection(url, username, password);
		
		
		
		List<Element> mappers = document.selectNodes("//mappers/mapper");
		for(Element mapper : mappers){
			String name = mapper.selectSingleNode("@name").getStringValue();
			String sql = mapper.selectSingleNode("sql").getText().trim();
			sqlanger.put(name, sql);
			
			// 预编译statement
			
			// 解析orm 进行映射
			
			// 返回映射后的pojo对象
			
		}
		
		
		Mapper mapper = new Mapper();
		List<Object> emps = mapper.selectAll(null);
		System.out.println(emps);
		
		System.out.println(connection);
		connection.close();
		
	}

}
